package edu.sdbi.judge.domain.vo;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {

    private int code;

    private String msg;

    private List<T> rows;

    private long total;

    public PageResult() {
    }

    public PageResult(int code, String msg, List<T> rows, long total) {
        this.code = code;
        this.msg = msg;
        this.rows = rows;
        this.total = total;
    }

    public static <T> PageResult<T> success(List<T> rows, long total) {
        return new PageResult<>(0, "成功", rows, total);
    }

    public static <T> PageResult<T> success(List<T> rows) {
        long total = new PageInfo<>(rows).getTotal();
        return new PageResult<>(0, "成功", rows, total);
    }

}
